<template>
	<view class="body">
		<xk-header :headerbg="true" :back="true" title="修改密码"></xk-header>
		<view class="list-info">
			<view class="list-item">
				<view class="label">原密码</view>
				<input class="input-text" v-model="oldPassword" type="password" placeholder="请输入您的原密码" placeholder-style="color:#ccc"/>
			</view>
			<view class="list-item">
				<view class="label">新密码</view>
				<input class="input-text" v-model="newPassword" type="password" placeholder="请输入新密码" placeholder-style="color:#ccc"/>
			</view>
			<view class="list-item">
				<view class="label">确认密码</view>
				<input class="input-text" v-model="confirmPassword" type="password" placeholder="请输入确认密码" placeholder-style="color:#ccc"/>
			</view>
		</view>

		<view class="common-btn" @click="onSubmit()">确认提交</view>
	</view>
</template>
<script>
	import config from '@/common/config.js'
	import moment from 'moment'
	let regex = new RegExp('(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*[^a-zA-Z0-9]).{8,30}')
	export default {
		data() {
			return {
				oldPassword: "",
				newPassword: "",
				confirmPassword: ""
			};
		},
		onLoad(options) {
		},
		methods:{
			onSubmit() {
				if (!this.oldPassword) {
					this.$util.toast("请输入您的原密码")
					return;
				}
				if (!this.newPassword) {
					this.$util.toast("请输入新密码")
					return;
				}
				if(this.newPassword.length < 8){
					this.$util.toast('密码长度不能小于8位')
					return
				}
				console.log(this.newPassword, !regex.test(this.newPassword));
				if(!regex.test(this.newPassword)){
					this.$util.toast('密码中必须包含大小字母、数字、特称字符')
					return
				}
				if (!this.confirmPassword) {
					this.$util.toast("请输入确认密码")
					return;
				}
				if (this.newPassword !== this.confirmPassword) {
					this.$util.toast("新密码与确认密码不一致")
					return;
				}
				if (this.$util.isTenant()=='NOT_YET_TENANT') {
					this.$util.toast("您还不是租户，无法进行密码修改操作")
					return;
				}
				this.$util.confirm({
					content: "确认要进行密码修改操作？",
					confirmText: "确定"
				}).then(isConfirm => {
					if (isConfirm) {
						this.$util.post({
							url: "app/mySelf/updateForPassword",
							data: {
								oldPassword: this.oldPassword,
								newPassword: this.newPassword
							}
						}).then(res => {
							this.$util.toast("密码修改成功")
							uni.navigateBack()
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">

.list-info {
	margin: 20rpx 20rpx 0rpx 20rpx;

	.list-item {
		display: flex;
		background-color: #FFFFFF;
		border-radius: 10rpx;
		font-size: 28rpx;
		padding: 30rpx;
		font-size: 28rpx;
		color: #333;
		align-items: center;
		.label{
			width: 130rpx;
		}
		.input-text {
			color: #333;
			margin-left: 20rpx;
		}
	}
}
</style>
